using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 帧同步 场景：两个玩家每帧发送方向输入，所有客户端使用同样的逻辑计算位置。
/// </summary>
public struct PlayerInput
{
    public int playerId;
    public Vector2 moveDir;
}
// 帧输入包
public class FrameData
{
    public int frameId;
    public List<PlayerInput> inputs = new List<PlayerInput>();
}
/// <summary>
/// 帧同步：简化实现（Unity伪代码）
/// </summary>
public class FrameSyncManager : MonoBehaviour
{
    public int currentFrame = 0;
    public float frameInterval = 0.05f; // 20帧/s
    private float timer = 0f;
    void Update()
    {
        timer += Time.deltaTime;
        if (timer >= frameInterval)
        {
            timer -= frameInterval;
            SendInput();
        }
    }
    void SendInput()
    {
        Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
        //NetworkManager.SendToServer(new PlayerInput { playerId = myId, moveDir = input });
    }
    // 接收到某帧的所有输入
    void OnReceiveFrame(FrameData frame)
    {
        foreach (var input in frame.inputs)
        {
            //Player player = FindPlayer(input.playerId);
            //player.position += input.moveDir * player.speed * frameInterval;
        }
        currentFrame = frame.frameId;
    }
}